package com.gpframework.module.manufacture.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.manufacture.domain.GpProductionApplication;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.util.Date;

/**
 * @ClassName GpProductionApplicationReq
 * @Author gpframework
 * @Date 2023-12-04
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpProductionApplicationReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("需求单号")
     private String sn;
     @ApiModelProperty("类型： 1染厂需求 2加工需求 3采购需求")
     private String type;
     @ApiModelProperty("产品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String colour;
     @ApiModelProperty("审核状态： 0待审核 1好的 2已安排 3已回货 4暂不安排")
     private String auditStatus;
     @ApiModelProperty("审核人id")
     private Long auditId;
     @ApiModelProperty("审核人名称")
     private String auditName;
     @ApiModelProperty("审核备注")
     private String auditRemarks;
     @ApiModelProperty("备注")
     private String remarks;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty("开始时间")
     private Date startTime;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty("结束时间")
     private Date endTime;
     @ApiModelProperty("查询条件（订单号/客户名）")
     private String searchName;
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date searchDate;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpProductionApplication> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias+"create_time");
        }
        if (StringUtils.isNotBlank(this.getSn())){
        lqw.eq(alias+"sn" ,this.getSn());
        }
        if (StringUtils.isNotBlank(this.getType())){
        lqw.eq(alias+"type" ,this.getType());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getColour())){
        lqw.eq(alias+"colour" ,this.getColour());
        }
        if (StringUtils.isNotBlank(this.getAuditStatus())){
        lqw.eq(alias+"audit_status" ,this.getAuditStatus());
        }
        if (this.getAuditId() != null){
        lqw.eq(alias+"audit_id" ,this.getAuditId());
        }
        if (StringUtils.isNotBlank(this.getAuditName())){
            lqw.like(alias+"audit_name",this.getAuditName());
        }
        if (StringUtils.isNotBlank(this.getAuditRemarks())){
            lqw.like(alias+"audit_remarks",this.getAuditRemarks());
        }
        if (StringUtils.isNotBlank(this.getRemarks())){
            lqw.like(alias+"remarks",this.getRemarks());
        }
        if (this.getStartTime() != null && this.getEndTime() != null) {
            lqw.between(alias + "create_time", this.getStartTime(), this.getEndTime());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.colour", this.getSearchName()).or().like("gp.product_name", this.getSearchName()));
        }
        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
    }
}
